from typing import List


class Testcase:
    def __init__(self,cid,module,title,priority,condition,step,expected,actual):
        self.bug_id=[]
        self.cid=cid
        self.module=module
        self.title=title
        self.priority=priority
        self.condition=condition
        self.step=step
        self.expected=expected
        self.actual=actual
    def __str__(self):
        return f"用例编号{self.cid},功能模块{self.module},测试标题{self.title},优先级别{self.priority},前置条件{self.condition}, 测试步骤{self.step},预期结果{self.expected},实际结果{self.actual},关联Bug的ID{self.bug_id}"

    def __repr__(self):
        return f"用例编号{self.cid},功能模块{self.module},测试标题{self.title},优先级别{self.priority},前置条件{self.condition}, 测试步骤{self.step},预期结果{self.expected},实际结果{self.actual},关联Bug的ID{self.bug_id}"

class Bug:
    def __init__(self,bid,description,status):
        self.bid=bid
        self.description=description
        self.status=status

    def __str__(self):
        return f"Bug编号{self.bid},Bug描述{self.description}, Bug状态{self.status}"
    def __repr__(self):
        return f"Bug编号{self.bid},Bug描述{self.description}, Bug状态{self.status}"
class BugManager:
    def __init__(self):
        self.bugs:List=[]
    def list_bugs(self):
         print(f"{self.bugs}")

    def add_bug(self,bug:Bug):
        for i in self.bugs:
            if bug.bid in i.bid:
                return "添加失败"
            else:
                self.bugs.append(bug)

    def get_bug(self,bid):
        for i in self.bugs:
            if i.bid==bid:
                return f"{i}"
            else:
                return False
    def update_bug(self,bid,bug:Bug):
        for i,b in enumerate(self.bugs):
            if b.bid==bid:
                self.bugs[i]=bug
                return self.bugs
            else:
                return False

    def delete_bug(self,bid):
        for i,b in enumerate(self.bugs):
            if b.bid==bid:
                del self.bugs[i]
                return self.bugs
            else:
                return False

class TestcaseManager:
    def __init__(self):
        self.testcases:List=[]
    def list_testcases(self):
         print(f"{self.testcases}")

    def add_testcase(self,testcase:Testcase):
        for i in self.testcases:
            if testcase.cid in i.cid:
                return "添加失败"
            else:
                self.testcases.append(testcase)

    def get_testcase(self,cid):
        for i in self.testcases:
            if i.cid==cid:
                return f"{i}"
            else:
                return False
    def update_testcase(self,cid, testcase:Testcase):
        for i,b in enumerate(self.testcases):
            if b.cid==cid:
                self.testcases[i]=testcase
                return self.testcases
            else:
                return False

    def delete_testcase(self,cid):
        for i,b in enumerate(self.testcases):
            if b.cid==cid:
                del self.testcases[i]
                return self.testcases
    def search_testcases(self,module, priority, bug_id):
        for i in self.testcases:
            if i.module==module and i.priority==priority and i.bug_id==bug_id:
                return f"{i}"
            else:
                return False

if __name__ == '__main__':
    testcase_1=Testcase(1,"添加","添加数据","p1","运行函数","第一步","成功","成功")
    testcase_2=Testcase(2,"删除","删除数据","p1","运行函数","第二步","成功","成功")
    testcasemanager=TestcaseManager()
    testcasemanager.add_testcase(testcase_1)
    testcasemanager.add_testcase(testcase_2)


    print(testcasemanager.get_testcase(1))
    testcasemanager.update_testcase(1,Testcase(3, "添加", "添加数据", "p1", "运行函数", "第一步", "成功", "失败"))
    testcasemanager.list_testcases()
    testcasemanager.delete_testcase(2)
    testcasemanager.list_testcases()
    print(testcasemanager.search_testcases("添加", "p1", []))